﻿using System.Linq;

namespace Nxg.Blog.Core.ViewProjections.Admin {
    public class AuthorProfileViewModel {
        public string DisplayName { get; set; }

        public string Email { get; set; }
    }

    public class AuthorProfileViewProjection : IViewProjection<string, AuthorProfileViewModel> {
        private readonly DataContext _db;

        public AuthorProfileViewProjection (DataContext db) {
            _db = db;
        }

        public AuthorProfileViewModel Project (string input) {
            var author = _db.Author.SingleOrDefault (x => x.Email == input);
            if (author == null)
                return null;
            return new AuthorProfileViewModel {
                DisplayName = author.DisplayName,
                    Email = author.Email
            };
        }
    }
}